package com.example.lx6_3

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.example.base.entity.AddVisParam
import com.example.base.mvvm.BaseActivity
import com.example.lx6_3.databinding.ActivityAddVisBinding
import com.example.lx6_3.visit.VisitViewModel
import dagger.hilt.android.AndroidEntryPoint
import java.text.SimpleDateFormat

@AndroidEntryPoint
@Route(path = "/app/AddVisActivity")
class AddVisActivity : BaseActivity<ActivityAddVisBinding,VisitViewModel>() {

    val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    override fun initView() {
        binding.tvTi.setOnClickListener {
            val addVisParam = AddVisParam()
            addVisParam.appointmentTime = sdf.format(System.currentTimeMillis())
            addVisParam.visitorName = binding.etName.text.toString()
            addVisParam.phoneNumber = binding.etPhone.text.toString().toLong()
            addVisParam.idNumber = binding.etIdNumber.text.toString().toLong()
            addVisParam.purpose = binding.etDescription.text.toString()
            vm.getAddVisit(addVisParam)
        }
    }

    override fun initData() {
        vm.addVisitData.observe(this){
            ToastUtils.showLong("添加成功")
            finish()
        }
    }
}